#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define N 20

int mystrchr(char str[], char c);
int main(int argc, char *argv[])
{
	char str[N];
	char c;
	int ans;

	srand(time(NULL));
	
	//字符数组初始化
	for(int i = 0; i < N-1; i++){
		str[i] = 'a' + rand() % 26; 
		printf("%c ", str[i]);
	}
	str[N-1] = '\0';	
	printf("\n");
	
	printf("请输入你要查找的小写字母：");
	scanf("%c", &c);
	ans = mystrchr(str, c);
	if(ans != -1){
		printf("%c的下标为：%d\n", c, ans);
	}else{
		printf("找不到呢\n");
	}
	return 0;
}

int mystrchr(char str[], char c){
	int i;
	for(i = 0; str[i]; i++){
		if(str[i] == c){
			return i;
		}
	}
	return -1;
}

